package cn.smbms.controller;

import cn.smbms.pojo.Role;
import cn.smbms.service.role.RoleService;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@Controller
@RequestMapping(value = "/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @RequestMapping(value = "/list")
    public String list(HttpServletRequest request){
        List<Role> roleList=roleService.getRoleList();

        request.setAttribute("roleList", roleList);
        return "rolelist";
    }

    @RequestMapping("/JList")
    @ResponseBody
    public Object listToJSON(){
        List<Role> roleList=roleService.getRoleList();

        String roleListJsonStr=JSON.toJSONString(roleList);

        return roleListJsonStr;
    }
}
